param(
    [parameter(Mandatory=$True)]
    [String] $build
)
$buildPath = Join-Path $build Paper Assets
New-Item -Type Directory -Path $buildPath -Force
$visioDrawings = Get-ChildItem -Recurse -Filter "*.vsdx"
Write-Host "Converting Visio documents to PDF."
try
{
    $visio = New-Object -ComObject Visio.Application
    $visio.Visible = $False
 
    foreach ($drawing in $visioDrawings)
    {
        
        $pdfname = [IO.Path]::ChangeExtension($drawing.Name, '.pdf')
        $pdfname = Join-Path $buildPath $pdfname
        Write-Host "Converting $drawing to $pdfname."
        $document = $visio.Documents.Open($drawing.FullName)
        # http://msdn.microsoft.com/en-us/library/office/ff766893.aspx
        $document.ExportAsFixedFormat(1, $pdfname, 1, 0)
    }
}
catch
{
    Write-Error $_
}
finally
{
    if ($visio) 
    {
        $visio.Quit()
    }
}

$dotDrawings = Get-ChildItem  -Recurse -Filter "*.dot"
Write-Host "Converting dot source to PDF."
try
{
    foreach ($dot in $dotDrawings)
    {
        $pdfname = [IO.Path]::ChangeExtension($dot.Name, '.pdf')
        $pdfname = Join-Path $buildPath $pdfname
        # $pdfname = $dot.FullName -replace("\.dot$", ".pdf")
        Write-Host "Converting $dot to $pdfname."
        dot $dot.FullName -Tpdf > $pdfname
    }
}
catch
{
    Write-Error $_
}


Write-Host "Creating links for ordinary assets."
$pictures = Get-ChildItem -Recurse -Filter "*.png"
try 
{
    foreach ($picture in $pictures)
    {
        $link = Join-Path $buildPath $picture.Name
        Write-Host "Linking $picture to $link."
        New-Item -Type SymbolicLink -Path $link -Target $picture.FullName -Force
    }
}
catch 
{
    Write-Error $_
}

